use "C:\Subprovince Database 2"
keep if country=="Indonesia" & province=="Riau"
collapse (sum) wpd,by(subprov mdate)
bysort mdate: egen twpd=total(wpd)
gen sw=100*wpd/twpd
bysort subprov: egen rm=rank(mdate)
save "C:\z1",replace
keep if rm==13
egen rprov=rank(sw),field
keep subprov rprov
sort subprov
save "C:\z2",replace

use "C:\z1"
sort subprov
merge subprov using "C:\z2"
drop _merge
keep if rprov<6
keep wpd subprov mdate
save "C:\z3",replace

gen prov1=word(subprov,1)
gen prov2=word(subprov,2)
gen prov=prov1+prov2

drop subprov prov1 prov2  
gen sw=wpd
drop wpd
reshape wide sw,i(mdate) j(prov) string

*   swKampar swPelalawan swRokanHilir swRokanHulu swSiak
label variable swKampar "Kampar"
label variable swPelalawan "Pelalawan"
label variable swRokanHilir "Rokan Hilir"
label variable swRokanHulu "Rokan Hulu"
label variable swSiak "Siak"

* egen rm=rank(mdate),field
* drop if rm<14

drop if swSiak==0

line sw* mdate, lcolor(black red gren blue orange) lwidth(medthick) lpattern(dash_dot longdash solid shortdash dash) xtitle("") ysize(3) xsize(4.5) xtick(#5) xlabel(#5) legend(size(medium) rows(5))
graph export "C:\Indo Subprovs.wmf", replace


